home *** CD-ROM | disk | FTP | other *** search
/ Best of Shareware / Best of PC Windows Shareware 1.0 - Wayzata Technology (7111) (1993).iso / mac / ZIPPED / DOS / GRAPHICS / RAYSH386.ZIP / SRC / MEMORY.C < prev    next >
C/C++ Source or Header  |  1992-04-30  |  2KB  |  95 lines

  1. /*
  2.  * memory.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: memory.c,v 4.0 91/07/17 14:30:57 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    memory.c,v $
  19.  * Revision 4.0  91/07/17  14:30:57  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #ifdef SYSV
  24. #include <memory.h>
  25. #endif
  26. #include "common.h"
  27.  
  28. unsigned long TotalAllocated;
  29.  
  30. voidstar
  31. RayMalloc(bytes)
  32. unsigned bytes;
  33. {
  34.     voidstar res;
  35.  
  36.     TotalAllocated += bytes;
  37.  
  38.     res = (voidstar)malloc(bytes);
  39.     if (res == (voidstar)NULL)
  40.         RLerror(RL_PANIC,
  41.             "Out of memory trying to allocate %d bytes.\n",bytes,"","");
  42.     return res;
  43. }
  44.  
  45. voidstar
  46. Calloc(nelem, elen)
  47. unsigned nelem, elen;
  48. {
  49.     voidstar res;
  50.  
  51.     res = RayMalloc(nelem*elen);
  52.     bzero(res, (int)nelem*elen);
  53.     return res;
  54. }
  55.  
  56. void
  57. PrintMemoryStats(fp)
  58. FILE *fp;
  59. {
  60.     fprintf(fp,"Total memory allocated:\t\t%lu bytes\n",
  61.             TotalAllocated);
  62. }
  63.  
  64. /*
  65.  * Allocate space for a string, copy string into space.
  66.  */
  67. char *
  68. strsave(s)
  69. char *s;
  70. {
  71.     char *tmp;
  72.  
  73.     if (s == (char *)NULL)
  74.         return (char *)NULL;
  75.  
  76.     tmp = (char *)RayMalloc((unsigned)strlen(s) + 1);
  77.     (void)strcpy(tmp, s);
  78.     return tmp;
  79. }
  80.  
  81. #ifdef MULTIMAX
  82.  
  83. char *
  84. share_calloc(num, siz)
  85. int num;
  86. unsigned int siz;
  87. {
  88.     char *res;
  89.  
  90.     res = share_malloc(num*siz);
  91.     bzero(res, num*siz);
  92.     return res;
  93. }
  94. #endif
  95.